package service

import (
	"errors"
	"fmt"
	"github.com/go-xorm/xorm"
	"im_unitree/model"
	"log"
)

var DbEngin *xorm.Engine

func init() {
	driverName := "mysql"
	DsName := "root:15690126217@(192.168.3.13:3306)/im_unitree?charset=utf8"
	err := errors.New("")
	DbEngin, err = xorm.NewEngine(driverName, DsName)
	if err != nil && err.Error() != "" {
		log.Fatal(err.Error())
	}

	err = DbEngin.Ping()
	if err != nil {
		fmt.Println("fail to connect")
	} else {
		fmt.Println("success to connect")
	}
	// 是否显示SQL语句
	DbEngin.ShowSQL(true)
	DbEngin.SetMaxOpenConns(2)
	// 自动创建表结构
	DbEngin.Sync2(new(model.User), new(model.Contact), new(model.Community))
	fmt.Println("init data base done")
}
